layui.use(['form','jquery','layer'],function () {
    var form = layui.form;
    var $ = layui.$;
    var layer = layui.layer;

    //关闭按钮
    $('#close').click(function () {
        var layer = parent.layer;
        layer.close(layer.index);
    })

    //封停按钮
    $('#closure').click(function () {
        //开始时间赋值
        $('#startDate').val(setTime());
        var id = $('#userId').val();
        //更改用户状态
        $.ajax({
            url: '/login/updateUserStatus',
            data: {
                userId: id,
                status: 4
            },
            type: 'post',
            dataType: 'json',
            success: function (data) {
                //更改启用状态
                $.ajax({
                    url: '/login/updateUserEnable',
                    data: {
                        userId: id,
                        enabled: 2
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        //添加封停记录
                        $.ajax({
                            url: '/JsClosure/addClosureUser',
                            type: 'post',
                            data: form.val('closureUserForm'),
                            dataType: 'json',
                            success: function (data) {
                                var layer = parent.layer;
                                layer.close(layer.index);
                            }
                        });
                    }
                });
            }
        })

    });
    //获取 年月日 时分秒 星期
    function setTime(){
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var today = date.getDate();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        //当小时小于10时进行补零
        var currentTime = zeroFill(year) + '-' + zeroFill(month) + '-' + zeroFill(today) +  ' ' + zeroFill(hour) + ':' + zeroFill(minute) + ':' + zeroFill(second);
        return currentTime;
    }
    //补零
    function zeroFill(time){
        if(time < 10){
            time = '0' + time;
        }
        return time;
    }
})